package cn.hl.hm.controller;

import cn.hl.hm.dao.VehicleLengthMapper;
import cn.hl.hm.dao.VtVlMapper;
import cn.hl.hm.entity.*;
import cn.hl.hm.entity.backstage.TBackstageUserBean;
import cn.hl.hm.service.RouteService;
import cn.hl.hm.service.RouteVehiclePriceService;
import cn.hl.hm.service.VehicleTypeService;
import cn.hl.hm.util.InfoCode;
import cn.hl.hm.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
@Controller
@RequestMapping("/routeController")
public class RouteController {
	private static final Logger logger = LoggerFactory.getLogger(OrderController.class);

	private final static SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
	private final static SimpleDateFormat hhmmSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	@Autowired
	RouteService routeService;
	@Autowired
	VehicleTypeService  vehicleTypeService;
	@Autowired
	RouteVehiclePriceService rvpService;
	@Autowired
	VtVlMapper vtVlMapper;
	@Autowired
	VehicleLengthMapper vehicleLengthMapper;
	/**
	  * @Title: login  
	  * @Description:路线列表
	  * @date: 2017年1月4日
	  * @author: 星矢
	  * @param DriverAccount
	  * @param pass
	  * @param platformId
	  * @param request
	  * @param response
	  * @throws IOException void 
	  * @throws
	 */
	@CrossOrigin
	@RequestMapping(value = "/selectRouteList", method = RequestMethod.POST)
	public String selectRouteList( 
			HttpServletRequest request, HttpServletResponse response) throws IOException {
		logger.info("路线运价业务---运价管理——获取所有线路列表(加载搜索下拉框)---routeController/selectRouteList");
		request.setCharacterEncoding("UTF-8");
		try{
			Route r = new Route();
			r.setRouteStatus("0");
			List<Route> route = routeService.selectRoute(r);
			if (null != route&&route.size()>0) { 
				Result.ok(route, InfoCode.SUCCESS, response);
				return null;
			} else {
				Result.ok(null, InfoCode.FAILURE, response);
				return null;
			}
		}catch(Exception e){
			e.printStackTrace();
			Result.ok(null, InfoCode.FAILURE, response);
			return null;
		}
	}
	
	
	
	
	
	
	
//	  /**
//    * @Title: send  
//    * @Description:添加线路
//    * @date: 2017年1月5日
//    * @author: 星矢
//    * @throws
//   */
//	@RequestMapping(value = "/addRoute", method = RequestMethod.POST)
//	public String addRoute(
//        Route route,
//		HttpServletRequest request, HttpServletResponse response)  {
//		TBackstageUserBean ue = (TBackstageUserBean) request.getSession().getAttribute("BACKSTAGEUSER");
//		 String operName="";
//			if (ue != null) {
//				if(ue.gettBackstageUserEntity()!=null){
//					if (ue.gettBackstageUserEntity().getMailbox() != null || !"".equals(ue.gettBackstageUserEntity().getMailbox())) {
//						operName = ue.gettBackstageUserEntity().getMailbox();
//					} else {
//						operName = "";
//					}
//					route.setOperationUsername(operName);
//				}
//			}
// 
//		try{
//			route.setCreateTime(new Date());
//			route.setRouteStatus("0");
//			
//			int routeId = routeService.addRoute(route); // 添加路线
//			if(routeId>0){
//				// 获取车型  添加一条路线，需要获取所有车型，让该路线 包含所有车型(所有车均可跑这条路线)
//				VehicleType vt = new VehicleType();
//				vt.setStatus("0");
//				List<VehicleType>  vtList = vehicleTypeService.selectVehicleType(vt);
//				// 添加日期-车型-路线-价格表  该路线所有的车型都可以运输
//				for (VehicleType vehicleType : vtList) {
//					RouteVehiclePrice rvp = new RouteVehiclePrice();   
//					rvp.setPrice(new BigDecimal(0));
//					rvp.setRouteId(route.getId());
//					rvp.setDateTime(hhmmSdf.format(new Date()));
//					rvp.setVehicleTypeId(vehicleType.getId());
//					rvpService.addRouteVehiclePrice(rvp);
//				}
//				Result.ok(null, InfoCode.SUCCESS, response);
//				return null;
//			}else {
//				Result.ok(null, InfoCode.FAILURE, response);
//				return null;
//			}
//		}catch(Exception e){
//			e.printStackTrace();
//			Result.ok(null, InfoCode.FAILURE, response);
//			return null;
//		}
//		
//	}
//	  /**
//	    * @Title: send  
//	    * @Description:添加线路-- 旧版本：添加一条路线，需要获取所有车型，让该路线 包含所有车型(所有车均可跑这条路线) 
//	    * @date: 2017年1月5日
//	    * @author: 星矢
//	    * @throws
//	   */
//		@RequestMapping(value = "/addRoute", method = RequestMethod.POST)
//		public String addRoute(
//	        Route route,
//			HttpServletRequest request, HttpServletResponse response)  {
//			TBackstageUserBean ue = (TBackstageUserBean) request.getSession().getAttribute("BACKSTAGEUSER");
//			 String operName="";
//				if (ue != null) {
//					if(ue.gettBackstageUserEntity()!=null){
//						if (ue.gettBackstageUserEntity().getMailbox() != null || !"".equals(ue.gettBackstageUserEntity().getMailbox())) {
//							operName = ue.gettBackstageUserEntity().getMailbox();
//						} else {
//							operName = "";
//						}
//						route.setOperationUsername(operName);
//					}
//				}
//	 
//			try{
//				route.setCreateTime(new Date());
//				route.setRouteStatus("0");
//				int routeId = routeService.addRoute(route); // 添加路线
//				if(routeId>0){
//					// 获取车型  添加一条路线，需要获取所有车型，让该路线 包含所有车型(所有车均可跑这条路线)
//					List<VtVl> vvList = vtVlMapper.selectVtVlList(null);
//					// 添加日期-车型-路线-价格表  该路线所有的车型都可以运输
//					for (VtVl vv : vvList) {
//						RouteVehiclePrice rvp = new RouteVehiclePrice();   
//						rvp.setPrice(new BigDecimal(0));
//						rvp.setRouteId(route.getId());
//						rvp.setDateTime(hhmmSdf.format(new Date()));
//						rvp.setVtVlId(vv.getId());
//						rvpService.addRouteVehiclePrice(rvp);
//					}
//					Result.ok(null, InfoCode.SUCCESS, response);
//					return null;
//				}else {
//					Result.ok(null, InfoCode.FAILURE, response);
//					return null;
//				}
//			}catch(Exception e){
//				e.printStackTrace();
//				Result.ok(null, InfoCode.FAILURE, response);
//				return null;
//			}
//			
//		}
	
	 /**
	    * @Title: send  
	    * @Description:添加线路-- 新版本：添加一条路线，需要获取所有车型，所有车长 均可跑这条路线
	    * @date: 2017年1月5日
	    * @author: 星矢
	    * @throws
	   */
		@RequestMapping(value = "/addRoute", method = RequestMethod.POST)
		public String addRoute(
	        Route route,
			HttpServletRequest request, HttpServletResponse response)  {
			logger.info("路线运价业务---添加线路---routeController/addRoute");
			TBackstageUserBean ue = (TBackstageUserBean) request.getSession().getAttribute("BACKSTAGEUSER");
			 String operName="";
				if (ue != null) {
					if(ue.gettBackstageUserEntity()!=null){
						if (ue.gettBackstageUserEntity().getMailbox() != null || !"".equals(ue.gettBackstageUserEntity().getMailbox())) {
							operName = ue.gettBackstageUserEntity().getMailbox();
						} else {
							operName = "";
						}
						route.setOperationUsername(operName);
					}
				}
	 
			try{
				route.setCreateTime(new Date());
				route.setRouteStatus("0");
				int routeId = routeService.addRoute(route); // 添加路线
				if(routeId>0){
					
//					Route r = new Route();
//					r.setRouteStatus("0");
//					VehicleType param = new VehicleType();
//					param.setStatus("0");
//					List<Route> routeList = routeService.selectRoute(r);
//					
//					List<VehicleType> vehicleTypeList = vehicleTypeService.selectVehicleType(param);
//					
//					List<VehicleLength> vehicleLengthList = vehicleLengthMapper.selectVehicleLength();
//					
//					for (Route route2 : routeList) {
//						for (VehicleType vehicleType : vehicleTypeList) {
//							for (VehicleLength vehicleLength : vehicleLengthList) {
//			
//							}
//						}
//					}
					// 获取车型  添加一条路线，需要获取所有车型，让该路线 包含所有车型(所有车均可跑这条路线)
					List<VtVl> vvList = vtVlMapper.selectVtVlList(null);
					// 添加日期-车型-路线-价格表  该路线所有的车型都可以运输
					for (VtVl vv : vvList) {
						RouteVehiclePrice rvp = new RouteVehiclePrice();   
						rvp.setPrice(new BigDecimal(0));
						rvp.setRouteId(route.getId());
						rvp.setDateTime(hhmmSdf.format(new Date()));
						rvp.setVtVlId(vv.getId());
						rvpService.addRouteVehiclePrice(rvp);
					}
					Result.ok(null, InfoCode.SUCCESS, response);
					return null;
				}else {
					Result.ok(null, InfoCode.FAILURE, response);
					return null;
				}
			}catch(Exception e){
				e.printStackTrace();
				Result.ok(null, InfoCode.FAILURE, response);
				return null;
			}
			
		}
		
	 /**
    * @Title: send  
    * @Description:删除线路
    * @date: 2017年1月5日
    * @author: 星矢
    * @param appId
    * @param order
    * @param request
    * @param response
    * @return String 
    * @throws
   */
	@RequestMapping(value = "/deleteRoute", method = RequestMethod.POST)
	public String deleteRoute(
      @RequestParam Integer routeId,
		HttpServletRequest request, HttpServletResponse response)  {
		logger.info("路线运价业务---删除路线---routeController/deleteRoute");
		try{
			Route	route = new Route();
			route.setId(routeId);
			route.setRouteStatus("1");
			//route.setCreateTime(new Date());
			int delete = routeService.updateRoute(route);
			if(delete>0){
				Result.ok(null, InfoCode.SUCCESS, response);
				return null;
			}else {
				Result.ok(null, InfoCode.FAILURE, response);
				return null;
			}
		}catch(Exception e){
			e.printStackTrace();
			Result.ok(null, InfoCode.FAILURE, response);
			return null;
		}
		
	}
	 /**
    * @Title: send  
    * @Description:修改线路
    * @date: 2017年1月5日
    * @author: 星矢
    * @param appId
    * @param order
    * @param request
    * @param response
    * @return String 
    * @throws
   */
	@RequestMapping(value = "/updateRoutePrice", method = RequestMethod.POST)
	public String updateRoute(
      @RequestParam Integer routeId,
      Route route,
      @RequestParam String price,
      @RequestParam Integer vehicleTypeId,
		HttpServletRequest request, HttpServletResponse response)  {
		logger.info("路线运价业务---修改路线---routeController/updateRoutePrice");
		
		int i=0;
		try{
			RouteVehiclePrice rvp = new RouteVehiclePrice();
			rvp.setRouteId(routeId);
			rvp.setVtVlId(vehicleTypeId);
//			route.setId(routeId);
			rvp.setOperType(1);
			List<RouteVehiclePrice> rList  = rvpService.selectRouteVehiclePrice(rvp);
			if(rList!=null && rList.size()>0){
				RouteVehiclePrice r = rList.get(0);
				if((r.getPrice().toString()).equals("0.00")){ // 如果为0，说明是第一次设置该路线对应车型的价格，进行修改操作。如果不为0，说明之前修过过，则进行添加
					r.setPrice(new BigDecimal(price));
					r.setDateTime(hhmmSdf.format(new Date()));
				
					i= rvpService.updateRouteVehiclePrice(r);
					Result.ok(null, InfoCode.SUCCESS, response);
				}else{ // 执行新增
//					if(r.getPrice()!=new BigDecimal(price)){
						RouteVehiclePrice rvpAdd = new RouteVehiclePrice();
						rvpAdd.setDateTime(hhmmSdf.format(new Date()));
						rvpAdd.setPrice(new BigDecimal(price));
						rvpAdd.setRouteId(routeId);
						rvpAdd.setVtVlId(r.getVtVlId());
						i= rvpService.addRouteVehiclePrice(rvpAdd);
						Result.ok(null, InfoCode.SUCCESS, response);
//					}
				
				}
			}
			//route.setCreateTime(new Date());
//			int update = routeService.updateRoute(route);
			if(i>0){
				Result.ok(null, InfoCode.SUCCESS, response);
				return null;
			}else {
				Result.ok(null, InfoCode.FAILURE, response);
				return null;
			}
		}catch(Exception e){
			e.printStackTrace();
			Result.ok(null, InfoCode.FAILURE, response);
			return null;
		}
		
	}
	 /**
	    * @Title: send  
	    * @Description:运价管理——当日线路报价
	    * @date: 2017年1月5日
	    * @author: 星矢
	    * @param appId
	    * @param order
	    * @param request
	    * @param response
	    * @return String 
	    * @throws
	   */
		@RequestMapping(value = "/currentRoutePrice", method = RequestMethod.POST)
		public String currentRoutePrice(
				String routeId,String vehicleName,Integer vtId,
			HttpServletRequest request, HttpServletResponse response)  {
			logger.info("路线运价业务---运价管理——当日线路报价---routeController/currentRoutePrice");
			try{
				Route r = new Route();
				r.setRouteStatus("0");
				if(routeId!=null){
					r.setId(Integer.parseInt(routeId));
				}
				List<Route> route = routeService.selectRoute(r);
				Map<String,List<RouteVehiclePriceVO>> routeVehiclePriceMap = new HashMap<String,List<RouteVehiclePriceVO>>();
				if (null != route&&route.size()>0) { 
					List<RouteVehiclePriceVO> rvoList   = new ArrayList<>();
					for (Route route2 : route) {
						RouteVehiclePrice rvp = new RouteVehiclePrice();
						rvp.setRouteId(route2.getId());
						rvp.setOperType(1);
						if(vehicleName!=null && !vehicleName.equals("")){
							rvp.setVehicleName(vehicleName);
						}
						if(vtId!=null && vtId!=0){
							rvp.setVtId(vtId);
							}
						List<RouteVehiclePrice> rList  = rvpService.selectRouteVehiclePrice(rvp);
						RouteVehiclePriceVO  rvo = new RouteVehiclePriceVO();
						rvo.setRoute(route2);
						rvo.setrList(rList);
						rvoList.add(rvo) ;
					}  
					//routeVehiclePriceMap.put("rvoList", rvoList);
					Result.ok(rvoList, InfoCode.SUCCESS, response);
					return null;
				} else {
					Result.ok(null, InfoCode.FAILURE, response);
					return null;

				}
			}catch(Exception e){
				e.printStackTrace();
				Result.ok(null, InfoCode.FAILURE, response);
				return null;
			}
		}
		
			/**
			 * 运价管理——车型运价管理
			 * @param routeId 路线ID
			 * @param vehicleTypeId 车型ID
			 * @param vlId 车长ID
			 * @param request
			 * @param response
			 * @return
			 */
			@RequestMapping(value = "/vehiclePrice", method = RequestMethod.POST)
			public String vehiclePrice(
					String routeId,
					Integer vehicleTypeId,
					Integer vlId,
				HttpServletRequest request, HttpServletResponse response)  {
				logger.info("路线运价业务---运价管理——车型运价管理---routeController/vehiclePrice");
				Result.ok(null, InfoCode.SUCCESS, response);
				return null;
//				try{
//					List<RouteVehiclePriceVO> rvoList   = new ArrayList<>();
//					Route r = new Route();
//					r.setRouteStatus("0");
//					if(routeId!=null){
//					   r.setId(Integer.parseInt(routeId));
//					}
//					// 获取路线信息【封装路线数据】
//					List<Route> route = routeService.selectRoute(r);
//
//					// 获取车长信息【封装车长数据】
//					VehicleLength vl = vehicleLengthMapper.selectByPrimaryKey(vlId);
//					if (null != route&&route.size()>0) {
//						for (Route route2 : route) {
//							RouteVehiclePrice rvp = new RouteVehiclePrice();
//							rvp.setRouteId(route2.getId());
//							if(vehicleTypeId!=null && vlId!=null){
//								// 获取车型和车长对应的关系ID ：vtvlId
//								VtVl vvObject = new VtVl();
//								vvObject.setVehicleTypeId(vehicleTypeId);
//								vvObject.setVehicleLengthId(vlId);
//								List<VtVl> vvList = vtVlMapper.selectVtVlList(vvObject);
//								if(vvList!=null && vvList.size()>0){
//									rvp.setVtVlId((vvList.get(0).getId()));
//								}
//							}
//							// 根据路线ID和vtvlId查询每日价格列表
//							List<RouteVehiclePrice> rList  = rvpService.selectRouteVehiclePriceByRouteId(rvp);
//							for (RouteVehiclePrice routeVehiclePrice : rList) {
//								// 封装前段展示数据
//								RouteVehiclePriceVO  rvo = new RouteVehiclePriceVO();
//								rvo.setRoute(route2);
//								rvo.setVehicleName(routeVehiclePrice.getVehicleName());
//								rvo.setVehicleLength(String.valueOf(vl.getVehicleLength()));
//								RouteVehiclePrice rvpVehicle = new RouteVehiclePrice();
//								rvpVehicle.setVtVlId(routeVehiclePrice.getVtVlId());
//								if(routeId!=null){
//									rvpVehicle.setRouteId(Integer.parseInt(routeId));
//								}else{
//									rvpVehicle.setRouteId(routeVehiclePrice.getRouteId());
//								}
//// 								rvp.setRouteId(route2.getId());
//								//线路报价废弃
////								List<RouteVehiclePrice> vehicleList  = rvpService.selectRouteVehiclePriceByDayLast(rvpVehicle);
////
////								rvo.setrList(vehicleList);
//								if(!rvoList.contains(rvo)){
//									rvoList.add(rvo) ;
//								}
////									break;
//
//							}
//						}
//						Result.ok(rvoList, InfoCode.SUCCESS, response);
//						return null;
//					} else {
//						Result.ok(null, InfoCode.FAILURE, response);
//						return null;
//
//					}
//				}catch(Exception e){
//					e.printStackTrace();
//					Result.ok(null, InfoCode.FAILURE, response);
//					return null;
//				}
				
			} 
			
			/**
			    * @Title: send  
			    * @Description:运价管理——线路车辆报价
			    * @date: 2017年1月5日
			    * @author: 星矢
			    * @param appId
			    * @param order
			    * @param request
			    * @param response
			    * @return String 
			    * @throws
			   */
				@RequestMapping(value = "/routeVehiclePriceByDate", method = RequestMethod.POST)
				public String routeVehiclePriceByDate(
						String time,
						Integer vehicleTypeId,
						Integer vlId,
					HttpServletRequest request, HttpServletResponse response)  {
					logger.info("路线运价业务---运价管理-线路车辆报价---routeController/routeVehiclePriceByDate");
					Result.ok(null, InfoCode.SUCCESS, response);
					return null;
//					try{
//
//
//						VtVl vvObject = new VtVl();
//						vvObject.setVehicleTypeId(vehicleTypeId);
//						vvObject.setVehicleLengthId(vlId);
//						List<VtVl> vvList = vtVlMapper.selectVtVlList(vvObject);
//						// 获取车长信息【封装车长数据】
//						VehicleLength vl = vehicleLengthMapper.selectByPrimaryKey(vlId);
//						// 加载车名称，封装数据
//						List <VehicleType> vtList = null;
//						if(vehicleTypeId!=null){
//						VehicleType vt = new VehicleType();
//						vt.setId(vehicleTypeId);
//						vtList = vehicleTypeService.selectVehicleType(vt);
//						}
//						List<RouteVehiclePriceVO> rvoList   = new ArrayList<>();
//
//						RouteVehiclePriceVO  rvo = null;
//						if(vvList!=null && vvList.size()>0){
//						for (VtVl vv : vvList) {
//							rvo = new RouteVehiclePriceVO();
//							RouteVehiclePrice  rv = new RouteVehiclePrice();
//							rv.setVtVlId(vv.getId());
//							if(vtList!=null){
//								rvo.setVehicleName(vtList.get(0).getName());
//								rvo.setVehicleLength(String.valueOf(vl.getVehicleLength()));
//							}else{
//								rvo.setVehicleName("平板");
//							}
//							if(time!=null && !time.equals("")){
//								rv.setDateTime(time);
//								rvo.setTime(shortSdf.parse(time));
//							}else{
//								rvo.setTime(new Date());
//							}
//							List<RouteVehiclePrice> rvpList  = rvpService.selectRouteVehiclePriceByDate(rv);
//							rvo.setrList(rvpList);
//							if(!rvoList.contains(rvo)){
//								rvoList.add(rvo) ;
//							}
//						}
//						Result.ok(rvoList, InfoCode.SUCCESS, response);
//						return null;
//						} else {
//							Result.ok(null, InfoCode.FAILURE, response);
//							return null;
//						}
//					}catch(Exception e){
//						e.printStackTrace();
//						Result.ok(null, InfoCode.FAILURE, response);
//						return null;
//					}
				}
		 /**
		    * @Title: send  
		    * @Description:运价管理——获取当日线路最低报价
		    * @date: 2017年1月5日
		    * @author: 星矢
		    * @param appId
		    * @param order
		    * @param request
		    * @param response
		    * @return String 
		    * @throws
		   */
			@RequestMapping(value = "/currentRoutePriceForDriver", method = RequestMethod.POST)
			public String currentRoutePriceForDriver(Integer routeId,
				HttpServletRequest request, HttpServletResponse response)  {
				logger.info("线路业务---获取所有线路所有车型中当日最低的那个价格---routeController/currentRoutePriceForDriver");
				try{
					RouteVehiclePrice rvp = new RouteVehiclePrice();
					rvp.setRouteId(routeId);
					 List<RouteVehiclePrice> rList  = rvpService.selectRouteVehiclePriceForDriver(rvp);
					 if(rList!=null && rList.size()>0){
						    Result.ok(rList, InfoCode.SUCCESS, response);
							return null;
					} else {
						Result.ok(null, InfoCode.FAILURE, response);
						return null;
					}
				}catch(Exception e){
					e.printStackTrace();
					Result.ok(null, InfoCode.FAILURE, response);
					return null;
				}
			}
					
					
	 /**
	    * @Title: send  
	    * @Description:运价管理——获取某条线路的运价信息
	    * @date: 2017年1月5日
	    * @author: 星矢
	    * @param appId
	    * @param order
	    * @param request
	    * @param response
	    * @return String 
	    * @throws
	   */
		@RequestMapping(value = "/routeVehiclePriceByConditionForDriver", method = RequestMethod.POST)
		public String routeVehiclePriceByConditionForDriver(Integer routeId,Integer vehicleTypeId,Integer vehicleLengthId, Integer type,
			HttpServletRequest request, HttpServletResponse response)  {
			logger.info("线路业务---获取某条线路的运价信息---routeController/routeVehiclePriceByConditionForDriver");
			try{
				RouteVehiclePrice rvp = new RouteVehiclePrice();
				rvp.setRouteId(routeId);
				VtVl vv = new VtVl();
				vv.setVehicleTypeId(vehicleTypeId);
				vv.setVehicleLengthId(vehicleLengthId);
				List<VtVl> l  = vtVlMapper.selectVtVlList(vv);
				
				if(l==null || l.size()==0){
					 Result.ok(null, InfoCode.VEHICLE_ERROR, response);
				}else{
					rvp.setVtVlId(l.get(0).getId());
				}
				 List<RouteVehiclePrice> rList = null;
				if(type!=null){
					if(type ==1){
						rList  = rvpService.selectRouteVehiclePriceByConditionForBackSendOrder(rvp);
					}
				}else{
					rList  = rvpService.selectRouteVehiclePriceByConditionForDriver(rvp);
				}
				 
				 if(rList!=null && rList.size()>0){
					    Result.ok(rList, InfoCode.SUCCESS, response);
						return null;
				} else {
					Result.ok(null, InfoCode.SUCCESS, response);
					return null;
				}
			}catch(Exception e){
				e.printStackTrace();
				Result.ok(null, InfoCode.FAILURE, response);
				return null;
			}
			
		}
		
		 /**
		    * @Title: send  
		    * @Description:根据车型查询 车长
		    * @date: 2017年1月5日
		    * @author: 星矢
		    * @param appId
		    * @param order
		    * @param request
		    * @param response
		    * @return String 
		    * @throws
		   */
			@RequestMapping(value = "/getVlByVt", method = RequestMethod.POST)
			public String getVlByVt(Integer vehicleTypeId,
				HttpServletRequest request, HttpServletResponse response)  {
				logger.info("线路业务---根据车型获取可用的车长信息---routeController/getVlByVt");
				try{
					VtVl vv = new VtVl();
					vv.setVehicleTypeId(vehicleTypeId);
					List<VtVl> l  = vtVlMapper.selectVtVlList(vv);
					if(l==null || l.size()==0){
						 Result.ok(null, InfoCode.SUCCESS, response);
						 return null;
					}else{
						 Result.ok(l , InfoCode.SUCCESS, response);
						 return null;
					}
					 
				}catch(Exception e){
					e.printStackTrace();
					Result.ok(null, InfoCode.FAILURE, response);
					return null;
				}
				
			}
		
//		@RequestMapping(value = "/addRVP", method = RequestMethod.POST)
//		public void addRVP() {
//			
//			// 获取所有
//			List<VehicleType>  vtList = vehicleTypeService.selectVehicleType(null);
//			
//			// 获取所有路线
//			List<Route> routeList = routeService.selectRoute(null);
//			 
//			for (VehicleType vehicleType : vtList) {
//				
//				RouteVehiclePrice rvp = new RouteVehiclePrice();
//				rvp.setVehicleTypeId(vehicleType.getId());
//				
//				for (Route route : routeList) {
//					rvp.setRouteId(route.getId());
//					// 获取某个车型对应某个路线是否存在当日的日期的价格，如果不存在，则新增一条今日的数据
//					List <RouteVehiclePrice> rvpList = rvpService.selectRouteVehiclePriceForAddQuartz(rvp);
//					
//					 // 不存在，新增一条今日的数据
//					if(rvpList == null || rvpList.size()==0){ 
//						List <RouteVehiclePrice> rvpOldList = rvpService.selectRouteVehiclePriceByRouteId(rvp);
//						if(rvpOldList!=null && rvpOldList.size()>0){
//							
//							// 获取昨日最新的一条数据作为今日需要新增的rvpNew对象
//							RouteVehiclePrice rvpNew= rvpOldList.get(0); 
//							rvpNew.setDateTime(hhmmSdf.format(new Date()));
//							rvpNew.setId(null);
//							rvpService.addRouteVehiclePrice(rvpNew);
//						}else{
//							// 获取昨日最新的一条数据作为今日需要新增的rvpNew对象
//							RouteVehiclePrice rvpNew= new RouteVehiclePrice(); 
//							    rvpNew.setVehicleTypeId(vehicleType.getId());
//							    rvpNew.setRouteId(route.getId());
//							    rvpNew.setPrice(new BigDecimal(0.01));
//							  
//							rvpNew.setDateTime(  hhmmSdf.format(new Date()));
//							rvpNew.setId(null);
//							rvpService.addRouteVehiclePrice(rvpNew);
//						}
//					}
//					
//					
//				}
//				 
//			}
//		}
		@RequestMapping(value = "/addRVP", method = RequestMethod.POST)
		public void addRVP() {
			// 获取所有
//			List<VehicleType>  vtList = vehicleTypeService.selectVehicleType(null);
			List<VtVl> vvList = vtVlMapper.selectVtVlList(null);
			
			// 获取所有路线
			List<Route> routeList = routeService.selectRoute(null);
			 
			for (VtVl vv : vvList) {
				
				RouteVehiclePrice rvp = new RouteVehiclePrice();
				rvp.setVtVlId(vv.getId()); 
				
				for (Route route : routeList) {
					rvp.setRouteId(route.getId());
					// 获取某个车型对应某个路线是否存在当日的日期的价格，如果不存在，则新增一条今日的数据
					List <RouteVehiclePrice> rvpList = rvpService.selectRouteVehiclePriceForAddQuartz(rvp);
					
					 // 不存在，新增一条今日的数据
					if(rvpList == null || rvpList.size()==0){ 
						List <RouteVehiclePrice> rvpOldList = rvpService.selectRouteVehiclePriceByRouteId(rvp);
						if(rvpOldList!=null && rvpOldList.size()>0){
							
							// 获取昨日最新的一条数据作为今日需要新增的rvpNew对象
							RouteVehiclePrice rvpNew= rvpOldList.get(0); 
							rvpNew.setDateTime(hhmmSdf.format(new Date()));
							rvpNew.setId(null);
							rvpService.addRouteVehiclePrice(rvpNew);
						}else{
							// 获取昨日最新的一条数据作为今日需要新增的rvpNew对象
							RouteVehiclePrice rvpNew= new RouteVehiclePrice(); 
							    rvpNew.setVtVlId(vv.getId());
							    
							    rvpNew.setRouteId(route.getId());
							    rvpNew.setPrice(new BigDecimal(0.01));
							  
							rvpNew.setDateTime(  hhmmSdf.format(new Date()));
							rvpNew.setId(null);
							rvpService.addRouteVehiclePrice(rvpNew);
						}
					}
					
					
				}
				 
			}
		}
		
		
		/**
		  * @Title: login  
		  * @Description:路线列表
		  * @date: 2017年1月4日
		  * @author: 星矢
		  * @param DriverAccount
		  * @param pass
		  * @param platformId
		  * @param request
		  * @param response
		  * @throws IOException void 
		  * @throws
		 */
		@RequestMapping(value = "/selectRouteListKY", method = RequestMethod.GET
				)
		public String selectRouteListKY( String kyStr,
				HttpServletRequest request, HttpServletResponse response) throws IOException {
			request.setCharacterEncoding("UTF-8");
			try{
				Route r = new Route();
				r.setRouteStatus("0");
				String rJson="";
				List<Route> route = routeService.selectRoute(r);
				String ss = request.getParameter("callback");
				if (null != route&&route.size()>0) { 
					net.sf.json.JSONArray jsonArray = net.sf.json.JSONArray.fromObject(route);
					rJson = "jsonpCallback({\"state\":{\"stateCode\":0,\"stateMessage\":\"成功！\"},\"data\":"+jsonArray.toString()+"})";
					response.getWriter().print(rJson);
					return null;
				} else {
					Result.ok(null, InfoCode.FAILURE, response);
					return null;
				}
			}catch(Exception e){
				e.printStackTrace();
				Result.ok(null, InfoCode.FAILURE, response);
				return null;
			}
		}
		
		
		
		
		
		
		
}
